package cn.jiyun.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(Model model){
        //封装模型数据
        model.addAttribute("username","tom");
        model.addAttribute("msg","asdfasfqwtasdfas");
        model.addAttribute("sex","男");
        model.addAttribute("birthday",new Date());
        System.out.println(new Date());

        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        model.addAttribute("list",list);

        //返回值：是模板名称
        return "hello";
    }

    @GetMapping("/demo/name/{id}")
    public String demo(@PathVariable("id") Integer id){
        System.out.println("id值是："+id);
        return "hello";
    }
}
